<?php 
	$customerid=Mage::getSingleton('customer/session')->getCustomerId();
	$isPartner= Mage::getModel('marketplaceprofile/marketplaceprofile')->isPartner($customerid);
	if($isPartner==1){?>
<link href="<?php echo $this->getSkinUrl('Customerpartner/css/global.css'); ?>" rel="stylesheet" type="text/css" />
<link href="<?php echo $this->getSkinUrl('Customerpartner/css/stylespagination.css'); ?>" rel="stylesheet" type="text/css" />
<link href="<?php echo $this->getSkinUrl('Customerpartner/css/webkul-global.css'); ?>" rel="stylesheet" type="text/css" />
<script type="text/javascript">
if (typeof jQuery == 'undefined'){
    document.write(unescape("%3Cscript src='http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js' type='text/javascript'%3E%3C/script%3E"));
}
</script>
<script src="<?php echo $this->getSkinUrl('Customerpartner/js/jquery.pajinate.js'); ?>" type="text/javascript"></script>
<?php 
    $userId=Mage::getSingleton('customer/session')->getCustomer()->getId();
	$collection = Mage::getResourceModel('marketplacepartner/userdata_collection');
	$collection->getSelect()->where('userid ='.$userId);
	echo $this->getMessagesBlock()->getGroupedHtml();
	?>
<div class="WK_product_background">
	<fieldset class="group-select">		
		<div id="customerpartner-products">
			<h4 class="WK_textcolor"><?php echo Mage::helper('marketplacepartner')->__('Edit Product') ?></h4>
			<div id="WK_paging_container7">
				<div class="WK_page_navigation"></div>
				<p class="WK_headingbackground"><?php echo Mage::helper('marketplacepartner')->__('Product Information') ?></p>
			  <div class="WK_whole_postion_edit">
			  <div class="WK_tbodyingedit">
										
							<div class="WK_tdpadfirsteditheadingupper">
								<label for="name" class="WK_rightgapedithead"><?php echo Mage::helper('marketplacepartner')->__('Product Name')?></label> 
							</div>
							<div class="WK_tdpadfirsteditheadingupper">
								<label for="name"  class="WK_rightgapedithead"><?php echo Mage::helper('marketplacepartner')->__('Image')?></label> 
							</div>
							<div class="WK_tdpadfirsteditheadingupper">
								<label for="name"  class="WK_rightgapedithead"><?php echo Mage::helper('marketplacepartner')->__('Price')?></label> 
							</div>
							<div class="WK_tdpadfirsteditheadingupper">
								<label for="name" class="WK_rightgapedithead"><?php echo Mage::helper('marketplacepartner')->__('Weight')?></label> 
							</div>
							<div class="WK_tdpadfirsteditheadingupper">
								<label for="name" class="WK_rightgapedithead"><?php echo Mage::helper('marketplacepartner')->__('Stock')?></label> 
							</div>
							<div class="WK_tdpadfirsteditheadingupper">
								<label for="name" class="WK_rightgapedithead"><?php echo Mage::helper('marketplacepartner')->__('Status')?></label> 
							</div>
							<div class="WK_tdpadfirsteditheadingupper">
								<label for="name" class="WK_rightgapedithead"><?php echo Mage::helper('marketplacepartner')->__('Qty. Sold')?></label> 
							</div>
							<div class="WK_tdpadfirsteditheadingupper">
								<label for="name" class="WK_rightgapedithead"><?php echo Mage::helper('marketplacepartner')->__('Earn Amount')?></label> 
							</div>
							<div class="WK_tdpadfirsteditheadingupper">
								<label for="name" class="WK_rightgapedithead"><?php echo Mage::helper('marketplacepartner')->__('Action')?></label> 
							</div>
						</div>	
						<div class="WK_tbodyingedit_content">
					<?php 
	foreach($collection as $data)
		{  
		$mageid=$data['mageproductid'];
		$products = Mage::getModel('catalog/product')->load($mageid);
		$productMediaConfig = Mage::getModel('catalog/product_media_config');
		
		
						$checkeven=0;
						$i=0;
						
							?>
							<div class="<?php if($checkeven%2==0)echo 'even-prod';else echo 'odd-prod';?> ex2">
								<div class="WK_tdpadfirstedit"><label for="name" class="WK_rightgapeditblue"><?php ((strlen($products->getName())) > 7) ? substr($products->getName(), 0, 7)."..." : $products->getName();  ?>
								<?php $l=strlen($products->getName()); if($l>7){ echo substr($products->getName(),0,7)."..";}else {echo $products->getName();} ?>
								</label>
								</div>
								<?php 
								if($productMediaConfig->getMediaUrl($products->getImage())){?>
								<div class="WK_tdpadfirstedit"><img src="<?php echo $productMediaConfig->getMediaUrl($products->getImage());?>" width="45px" height="35px" /></div>			
								<?php
								}else{?>
								<div class="WK_tdpadfirstedit"><label for="name" class="WK_rightgapedit"><?php echo Mage::helper('marketplacepartner')->__('Pending')?></label></div>
									<?php } ?>
								<div class="WK_tdpadfirstedit"><label for="name" class="WK_rightgapedit"><?php echo Mage::app()->getStore()->formatPrice($products->getPrice())?></label></div>
								<div class="WK_tdpadfirstedit"><label for="name" class="WK_rightgapedit"><?php echo sprintf("%01.2f", $products->getWeight());?></label></div>
								<div class="WK_tdpadfirstedit">
									<label for="name" class="WK_rightgapedit">
									<?php
											$eachchildIds = Mage::getModel('catalog/product')->load($products->getId());
											echo $eachchildIds->getStockItem()->getQty();
									?>
									</label>
								</div>
								<?php if($products->getStatus()==2) {
										$row = Mage::getModel('marketplacepartner/marketplacepartner')->getProductType($products->getEntityId());
								?> 			
								<div  class="WK_tdpadfirstedit"><label for="name" class="WK_rightgapedit"><?php echo Mage::helper('marketplacepartner')->__('Pending')?></label></div>
								<div  class="WK_tdpadfirstedit"><label for="name" class="WK_rightgapedit"><?php echo Mage::helper('marketplacepartner')->__('Pending')?></label></div>
								<div  class="WK_tdpadfirstedit"><label for="name" class="WK_rightgapedit"><?php echo Mage::helper('marketplacepartner')->__('Pending')?></label></div>
								<div style="text-align:center;" class="WK_tdpadfirstedit"><label for="name" class="WK_rightgapedit">
								<a title="Edit unapproved Product" onclick="editapproveme('<?php echo $products->getId();?>','<?php echo $products->getEntityId(); ?>','<?php echo $products->getTypeID();?>')"><img src="<?php echo $this->getSkinUrl('customerurlpic/edit.gif'); ?>" /></a> || <a title="Delete Magento Product" onclick="deleteme('<?php echo $products->getEntityId(); ?>')"><img src="<?php echo $this->getSkinUrl('customerurlpic/delete.gif'); ?>" /></a></label></div>	
								<?php } else{ 
								$id=$products->getId();
								$productsolddetail=Mage::getModel('marketplacepartner/productsales')->getProductSalesDetailById($id);
								$qtycom=0;
								$com=0;
								foreach($productsolddetail as $key){
									$qtycom+=$key['magequantity'];
									$com+=$key['actualparterprocost'];
								}
								?>
								<div class="WK_tdpadfirstedit"><label for="name" class="WK_rightgapedit"><?php echo Mage::helper('marketplacepartner')->__('Approved')?></label></div>
								<?php $QtyandEarned = Mage::getModel('marketplacepartner/userdata')->amountEarned($products->getEntityId());
								$QtyandSold = Mage::getModel('marketplacepartner/userdata')->quantitySold($products->getEntityId());?>
								<div align="center" class="WK_tdpadfirstedit"><label for="name" class="WK_rightgapedit"> <?php echo $QtyandSold; ?></label></div>
								<div align="center" class="WK_tdpadfirstedit">
									<label for="name" class="WK_rightgapedit"><?php echo $QtyandEarned; ?></label>
								</div>
								<div style="text-align:center;" class="WK_tdpadfirstedit"><label class="WK_rightgapedit">
								<a title="Edit Magento Product" onclick="editapproveme('<?php echo $products->getId();?>','<?php echo $products->getEntityId(); ?>','<?php echo $products->getTypeID();?>')"><img src="<?php echo $this->getSkinUrl('customerurlpic/edit.gif'); ?>" /></a>||<a title="<?php echo Mage::helper('marketplacepartner')->__('Delete Magento Product')?>" onclick="deleteme('<?php echo $products->getId();?>')"><img src="<?php echo $this->getSkinUrl('customerurlpic/delete.gif'); ?>" /></a></label></div>
							 <?php $checkeven++;} ?>
					
						</div>
						<?php } ?>
					 </div>
				<p class="headingback">
					<a href="javascript:;" onclick="javascript: window.history.back();" class="left">&laquo; <?php echo Mage::helper('marketplacepartner')->__('Back') ?></a>
				</p>
				</div>	
			</div> 
		</div>	
	
	</fieldset>
</div>

<script type="text/javascript">
	jQuery.noConflict();	
	jQuery(document).ready(function(){
		jQuery('#WK_paging_container7').pajinate({
			num_page_links_to_display : 5,
			items_per_page : 10	
		});
	});	
	
</script> 
<script>
	function editme(pid,producttype){
		if(producttype=='simple')
			{window.location = "<?php echo $this->getUrl('customer/products/editsimple/') ?>".concat("id/",pid,"/");}
		if(producttype=='virtual')
			{window.location = "<?php echo $this->getUrl('customer/products/editvirtual/') ?>".concat("id/",pid,"/");}
		if(producttype=='downloadable')
			{window.location = "<?php echo $this->getUrl('customer/products/editdownload/') ?>".concat("id/",pid,"/");}		
						
	}
	function editapproveme(approvid,entityid,appproducttype){				
		var dicisionapp=confirm('Sure Want To Edit Magento Product');
		if(appproducttype=='simple')
			{window.location = "<?php echo $this->getUrl('customer/products/editapprovedsimple/') ?>".concat("id/",approvid);}
		if(appproducttype=='virtual')
			{window.location = "<?php echo $this->getUrl('customer/products/editapprovedvirtual/') ?>".concat("id/",approvid);}
		if(appproducttype=='downloadable')
			{window.location = "<?php echo $this->getUrl('customer/products/editapproveddownload/') ?>".concat("id/",approvid);}
	}
	function deleteme(pid)	{
		var dicision=confirm('<?php echo Mage::helper('marketplacepartner')->__('Sure Want To Delete Magento Product')?>');
		if(dicision==true)
			window.location = "<?php echo $this->getUrl('customer/products/delete/') ?>".concat("id/",pid);		
	}
	function deleteapproveme(approvid){				
		var dicisionapp=confirm('<?php echo Mage::helper('marketplacepartner')->__('Sure Want To Delete Magento Product'); ?>');
		if(dicisionapp==true)
		{window.location = "<?php echo $this->getUrl('customer/products/deleteapproved/') ?>".concat("id/",approvid);}
	}	
</script>
<?php }else{
	echo Mage::helper('marketplacepartner')->__("<h2 style='color:#ff0000;font-weight:600'>FOR BECOME SELLER CONTACT TO ADMIN..</h2>");
}?>